from apis.bzy import Bzy


class Ware(Bzy):
    def create_wx_ware(self, name):
        """
        创建微信仓库
        :param name:仓库名称
        :return:响应体
        """
        create_url = f"{self.base_url}/v1/wxorderware"
        json = {"name": name,
                "cutTime": "00:02", "wxGroupNickname": "we are 伐木嘞", "wxReceiveId": "wxid_9izu0ybeqnb622",
                "wxGroupSsid": "23263592649@chatroom", "exportTemplateId": "7100431", "pushExcelType": "0", "type": "0",
                "wxReceiveNickname": "！"}
        req = {
            "method": "POST",
            "url": create_url,
            "json": json,
            "headers": {
                "Authorization": self.token
            }
        }
        r = self.send_api(req)
        return r

    def create_third_ware(self, name):
        """
        创建第三方仓库
        :param name:仓库名称
        :return:响应体
        """
        create_url = f"{self.base_url}/v1/wxorderware"
        json = {"name": name, "exportTemplateId": "7100431", "type": "4",
                "qimenAccount": {"ownerCode": "123", "customerId": "123", "wareHouseCode": "123"}}
        req = {
            "method": "POST",
            "url": create_url,
            "json": json,
            "headers": {
                "Authorization": self.token
            }
        }
        r = self.send_api(req)
        return r

    def search_ware(self, name):
        """
        搜索仓库
        :param name: 仓库名称
        :return: 响应体
        """
        search_url = f"{self.base_url}/v1/wxorderware"
        req = {
            "method": "GET",
            "url": search_url,
            "params": {
                "name": name
            },
            "headers": {
                "Authorization": self.token
            }
        }
        r = self.send_api(req)
        return r

    def update_wx_ware(self, new_name, id):
        """
        修改微信仓库名称
        :param new_name: 仓库名称
        :param id: 仓库id
        :return: 响应体
        """
        update_url = f"{self.base_url}/v1/wxorderware/{id}"
        json = {"name": new_name,
                "type": "0", "cutTime": "00:02", "wxGroupNickname": "we are 伐木嘞",
                "wxReceiveId": "wxid_9izu0ybeqnb622", "wxGroupSsid": "23263592649@chatroom",
                "exportTemplateId": "7100431", "pushExcelType": "0", "wxReceiveNickname": "！"}
        req = {
            "method": "PUT",
            "url": update_url,
            "json": json,
            "headers": {
                "Authorization": self.token
            }
        }
        r = self.send_api(req)
        return r

    def update_third_ware(self, new_name, id):
        """
        修改第三方仓库名称
        :param new_name: 仓库名称
        :param id: 仓库id
        :return: 响应体
        """
        update_url = f"{self.base_url}/v1/wxorderware/{id}"
        json = {"name":new_name,"type":"4","qimenAccount":{"customerId":"123"}}
        req = {
            "method": "PUT",
            "url": update_url,
            "json": json,
            "headers": {
                "Authorization": self.token
            }
        }
        r = self.send_api(req)
        return r

    def del_ware(self, id):
        """
        删除仓库
        :param id: 仓库id
        :return: 响应体
        """
        del_url = f"{self.base_url}/v1/wxorderware/{id}"
        req = {
            "method": "DELETE",
            "url": del_url,
            "headers": {
                "Authorization": self.token
            }
        }
        r = self.send_api(req)
        return r
